package com.jh3502.vivo.function.travelnew;

import android.support.annotation.NonNull;

import com.jh3502.vivo.base.BaseCallback;
import com.jh3502.vivo.base.BaseJson;
import com.jh3502.vivo.base.BasePresenter;
import com.jh3502.vivo.base.BaseView;

import java.util.Map;

/**
 * @author harisucici
 * @date 2017/6/19
 */

public class TravelNewPresenter extends BasePresenter<TravelNewPresenter.TravelNewView> {
    TravelNewModel mTravelNewModel;

    TravelNewView mTravelNewView;


    public void setTravelNewView(TravelNewView mTravelNewView) {
        this.mTravelNewView = mTravelNewView;

    }

    public void toSumtravel(Map<String, Object> body) {
        mTravelNewView.showLoadingDialog();
        if (mTravelNewModel == null) {
            mTravelNewModel = new TravelNewModel(mTravelNewView.getActContext());
        }

        mTravelNewModel.sumtravel(body, new BaseCallback(mTravelNewView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                mTravelNewView.sumtravelSuccess();
            }
        });
    }

    public void toGetTravelById(Map<String, Object> body) {
        mTravelNewView.showLoadingDialog();
        if (mTravelNewModel == null) {
            mTravelNewModel = new TravelNewModel(mTravelNewView.getActContext());
        }

        mTravelNewModel.getTravelById(body, new BaseCallback(mTravelNewView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
//                mTravelNewView.getTravelByIdSuccess(
//                        new Gson().fromJson(baseJson.getObj().toString(),TravelNewBean.class));
                mTravelNewView.getTravelByIdSuccess(baseJson.getObj().toString());
            }
        });
    }

//    public void toUpload(List<File> files) {
//        if (mTravelNewModel == null) {
//            mTravelNewModel = new TravelNewModel(mTravelNewView.getActContext());
//        }
//
//        mTravelNewModel.upload(files, new Callback() {
//            @Override
//            public void onFailure(Call call, IOException e) {
//                mTravelNewView.dismissLoadingDialog();
//            }
//
//            @Override
//            public void onResponse(Call call, Response response) {
//                Gson gson = new Gson();
//                JsonReader jsonReader = new JsonReader(response.body().charStream());
//                BaseJson baseJson = gson.fromJson(jsonReader, BaseJson.class);
//                if (baseJson.getCode() == 0) {
//                    mTravelNewView.dismissLoadingDialog();
//                    List<String> photos = Utils.getInstance().jsa2listString(baseJson.getObj().toString());
//                    StringBuffer stringBuffer = new StringBuffer();
//                    for (String s : photos) {
//                        stringBuffer.append(s);
//                        stringBuffer.append(",");
//                    }
//                    mTravelNewView.uploadSuccess(stringBuffer.toString().substring(0, (stringBuffer.length() - 1)));
//                }
//            }
//        });
//
//    }


    @Override
    public void cancelCall() {

    }

    public interface TravelNewView extends BaseView {
        void sumtravelSuccess();

        void getTravelByIdSuccess(String s);
    }
}
